﻿Imports DTO
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data.SqlTypes
Public Class ChiTietPhieuNhapDAO

    Public Sub Them(ByVal ctpndto As ChiTietPhieuNhapDTO)


        'B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
        Dim cn As SqlConnection
        cn = DatabaseProvider.ConnectionData()
        'B3: Tao chuoi strSQL thao tac CSDL
        Dim strSQL As String
        strSQL = "Insert into CHITIETPHIEUNHAP(MaPhieuNhap,SoLuong,DonGiaNhap) values(?,?,?)"
        'B4: Thuc thi chuoi strSQL
        Dim cmd As New SqlCommand(strSQL, cn)

        cmd.Parameters.Add("@MaPhieuNhap", SqlDbType.Int)
        cmd.Parameters("@MaPhieuNhap").Value = ctpndto.MaPhieuNhap
        cmd.Parameters.Add("@SoLuong", SqlDbType.Int)
        cmd.Parameters("@SoLuong").Value = ctpndto.SoLuong
        cmd.Parameters.Add("@DonGiaNhap", SqlDbType.Int)
        cmd.Parameters("@DonGiaNhap").Value = ctpndto.DonGiaNhap

        cmd.ExecuteNonQuery()
        strSQL = "Select @@IDENTITY"
        cmd = New SqlCommand(strSQL, cn)
        ctpndto.MaCTPhieuNhap = cmd.ExecuteScalar()
        'B5: Dong ket noi CSDL
        cn.Close()
    End Sub
End Class
